﻿<%@ Page Title="" Language="C#" MasterPageFile="~/PIMMobile.master" AutoEventWireup="true" CodeFile="CreateUser.aspx.cs" Inherits="CreateUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script>

    function CreateNewAccount() {
        $('#createnewaccount').click(function () {
            if ($("#create_username").val() == '') {
                alert('Please input username or email!');
                $("#create_username").focus();
            }
            else if ($("#create_password").val() == '') {
                alert('Please input password');
                $("#create_password").focus();
            }
            else if ($("#confirm_create_password").val() == '') {
                alert('Please input password to confirm');
                $("#confirm_create_password").focus();
            }
            else if ($("#confirm_create_password").val() != $("#create_password").val()) {
                alert('Password is not mark!');
                $("#confirm_create_password").val("");
                $("#confirm_create_password").focus();
            }
            else {
                $.ajax({
                    type: "POST",
                    url: "PIMServices.asmx/CreateNewMember",
                    data: "{'_userName':'" + $("#create_username").val() + "','_password':'" + $("#create_password").val() + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (result) {
                        if (result.d == 'NotOK' || result.d == '') {
                            alert('Create a new user is failt!');
                        }
                        else {
                            self.location = "Default.aspx"
                        }
                    },
                    error: function (result) {
                        alert('Can not create a new user!');
                    }
                });
            }
        });
    }

    $(document).ready(function () {
        CreateNewAccount();
    });
    </script>

    <div style="margin-top:5%">
        <form method="post" action="#">
        <fieldset>
            <div>
                Email Address:
                <input name="email" id="create_username" class="textInputs" type="text" autocomplete="on" placeholder="Email address">
            </div>
            <div>
                Password:
                <input name="password" id="create_password" class="textInputs" type="password" placeholder="Password">
            </div>
            <div>
                Confirm password:
                <input name="confirmpassword" id="confirm_create_password" class="textInputs" type="password" placeholder="Password">
            </div>
        </fieldset>
        <div style="text-align:center; margin-top:5%">
            <input id="createnewaccount" class="save_button" value="Create account" type="button">
        </div>
        </form>
    </div>
</asp:Content>

